<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import updateDialog from "@/components/updateDialog/index.js";

export default {
  props: ["userId"],
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.List],
  data() {
    return {
      appWindow: window,
      apiUrl: {
        list: "mall-site-portal/member/listIntegralRecord",
        updateApi: "mall-site-portal/member/batchMemberIntegral",
      },
      assetTypeOptions: [], //资产类型数组
      currentTypeId: "", //当前选择的资产类型id

      mixinList_tableSearchConst: {
        memberId: "",
        typeId: "",
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      this.mixinList_loading = true;
      // 数据源 资产类型数组
      this.assetTypeOptions = await this.$vFN.Tools.getSelectListSource(
        {
          url: "mall-site-portal/member/getIntegralType",
        },
        window
      );

      // 反转数组
      this.assetTypeOptions = this.assetTypeOptions.reverse();

      console.error(this.assetTypeOptions);

      this.currentTypeId = this.assetTypeOptions[0].value;
      this.mixinList_tableSearchConst.typeId = this.assetTypeOptions[0].value;

      this.mixinList_tableSearchConst.memberId = this.userId;

      this.mixinList_getTable();
    },

    change(id_) {
      this.mixinList_tableSearchConst.typeId = id_;
      this.mixinList_getTable(1);
    },

    updateData() {
      let titleText_ = "";
      this.assetTypeOptions.forEach((item) => {
        if (item.value == this.currentTypeId) {
          titleText_ = item.label;
        }
      });

      updateDialog.init({
        titleText: titleText_,
        requestApi: this.apiUrl.updateApi,
        updateType: "Integral",
        integralId: this.currentTypeId,
        userArr: [this.userId],
        onSuccess: (res) => {
          this.mixinList_getTable();
        },
      });
    },
  },
};
</script>
